package com.business.business.config.webconfig;

import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.RequestContextListener;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class Interceptorconfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry)
    {
        //参数校验
        //registry.addInterceptor(new ParamsInterceptor());
        //权限校验
        //registry.addInterceptor(new AuthInterceptor());
    }

    /**
     * 监听器添加
     *
     * @return
     */
    @Bean
    public ServletListenerRegistrationBean<RequestContextListener> listenerRegist() {
        ServletListenerRegistrationBean<RequestContextListener> srb = new ServletListenerRegistrationBean<RequestContextListener>();
        // 添加监听器,在任意代码获取request等对象
        srb.setListener(new RequestContextListener());
        return srb;
    }
}
